//保存表格的实例对象
var tableI = null;

function aa(){
    tableI.reload();
}

layui.use(['table','form','laydate'], function () {
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;

    //监听顶部重置按钮
    // form.on('submit(cz)',function (d){
    //     $("[name=journalName]").val(undefined)
    //     $("[name=journalOperationList]").val(undefined)
    //     $("[name=journalOperation]").val(undefined)
    //     $("[name=timetable]").val(undefined)
    //     $("input").val('');
    //
    //     tableI.reload({
    //         url:'/logManagement/getOperationLog',
    //     },true)
    //     return false
    // })

    laydate.render({
        elem: '#hirthdate',
        type: 'date'
    })

    // 展示表格
    tableI = table.render({
        elem: '#operationLog',
        url: '/logManagement/getOperationLog',
        id: 'tableIn',
        page: {
            //       总条数  左箭头  显示的页数 右箭头  // 每页显示条数
            layout: ['count', 'prev', 'page', 'next', 'limit'],
            groups: 1,
            // 每页显示条数
            limit: 20,
            // 每页显示条数
            limits: [20, 30, 50]
        },
        cols: [[
            {field: '', title: '', type: 'checkbox',width: 48},
            {field: 'journalId', title: "序号", width: 80,sort: true},
            {field: 'journalName', title: "管理员名称", width: 230},
            {field: 'journalOperationList', title: "操作的列表", width: 200},
            {field: 'timeTable', title: "执行时间", width: 230,sort: true},
            {field: 'journalOperation', title: "操作类型", width: 190},
            {field: 'journalRemarks', title: "备注", width: 200},
            {title: '操作', toolbar: '#toolbtn', width: 200}
        ]],
        // 分页
        parseData:function (res){
            return{
                "code":res.code,
                "msg":res.msg,
                "count":res.count,
                "data":res.data
            };
        },
        toolbar: '#toolbarbtn'
    })

    //查询 重新渲染表格
    form.on('submit(commodityReviewSs)', function (d) {
        d=d.field;
        console.log(d)
        table.reload('tableIn',{
            where: {
                journalName: d.journalName,
                journalOperation: d.journalOperation,
                timeTable: d.timeTable
            }
        })
    })

    // 删除
    table.on('tool(test)', function (obj) {
        if (obj.event === 'delete') {
            layer.confirm('真的删除' + obj.data.journalName + '吗?', function (index) {
                $.ajax({
                    type: 'post',
                    url: '/logManagement/deleteOperationLog',
                    data: {"journalId": obj.data.journalId},
                    dataType: 'json',
                    success: function (res) {
                        layer.close(index);
                        tableI.reload();
                        if (res.start == 200){
                            layer.msg(res.msg,{time:500,icon:5})
                        }
                        else {
                            layer.msg(res.msg,{time:500,icon:6})
                        }
                    },
                    error: function (e) {
                        console.log("失败");
                        console.log(e);
                    }
                })
            })
        }
    })
})